<template>
  <div>
    <content-header title="在线学习"></content-header>
    <div class="tab-header xui-margin-top-lg" style="padding:10px;">
      <span>受众人群:</span>
      <category-tabs
        :tabList="tags"
        :tabIndex="Number(tagIndex)"
        @changeCategory="changeCategory"
      ></category-tabs>
    </div>
    <div class="list xui-margin-right-sm" v-for="(item, index) in listData" :key="index">
      <router-link :to="`${$route.path}/detail/${item.id}`">
        <div class="list__img xui-margin-xs">
          <img-box :width="202" :height="212" :imgSrc="item.imgUrl"></img-box>
        </div>
        <div class="list__text">
          <h4 class="xui-text-truncate">{{item.title}}</h4>
          <p class="xui-text-truncate-line-2 color-darken-gray">
            {{item.content | truncate(20)}}</p>
          <span class="people color-darken-gray">主讲人 | <span>{{item.name}}</span></span>
        </div>
        <ul class="tags" v-if="item.tagNames">
          <li  v-for="(i, index) in item.tagNames.split(',')" :key="index">
            <span>{{i}}</span>
          </li>
        </ul>
        <div class="bottom">
          <div>
            <i class="iconfont icon-user1 color-gray"></i>
            <span class="color-gray">{{item.learnNum || 0}}</span>
          </div>
          <span class="color-gray">{{item.stAct}}</span>
        </div>
      </router-link>
    </div>
  </div>
</template>
<script>
import ContentHeader from "../../../components/widge/content-header";
import CategoryTabs from "@/components/widge/category-tabs/tab-bar";
import ImgBox from "@/components/widge/img-box";
import pic from "../../../assets/images/learning/learning-guide-people-1.png";
import { getCourseList, getCourseTags } from "@/api/learning-online";

export default {
  mounted() {
    this.getCourseList();
    this.getCourseTags();
  },
  components: {
    ContentHeader,
    CategoryTabs,
    ImgBox
  },
  data() {
    return {
      dialogTableVisible: true,
      tagIndex: 0,
      pic,
      tags: [
        {
          index: 0,
          name: "全部"
        }
      ],
      items: [
        {
          name: "家庭"
        },
        {
          name: "成人"
        }
      ],
      listData: [],
      page: {
        index: 1,
        size: 10,
        count: 0
      }
    };
  },
  methods: {
    getCourseList() {
      getCourseList(this.tagIndex, this.page.index).then(res => {
        this.listData = res.data.recordsList;
        this.page.count = res.data.count;
      });
    },
    getCourseTags() {
      getCourseTags().then(res => {
        res.data.forEach(item => {
          let i = {};
          i.index = item.id;
          i.name = item.menuName;
          this.tags.push(i);
        });
      });
    },
    changeCategory(item) {
      this.tagIndex = item.index;
    }
  },
  watch: {
    tagIndex: function() {
      console.log(this.tagIndex);
      this.getCourseList();
    }
  }
};
</script>

<style lang="less" scoped>
.list {
  width: 448px;
  height: 228px;
  position: relative;
  /*margin-right: 30px;*/
  margin-top: 20px;
  float: left;
}

.list:nth-child(even) {
  margin-right: 0;
}

.list a {
  width: 448px;
  height: 228px;
  display: block;
  cursor: pointer;
  border: 2px solid #d2d2d2;
}

.list > a > div {
  float: left;
}

.list a:hover {
  border: 2px solid #dea630;
}

.list .list__text {
  width: calc(100% - 60px);
  position: absolute;
  top: 50%;
  right: 40px;
  margin-top: -88px;
}

.list .list__text h4 {
  font-size: 18px;
  font-weight: normal;
  margin-bottom: 15px;
  line-height: 1;
}

.list .list__text span,
p {
  font-size: 14px;
}

.list .list__text p {
  margin-bottom: 5px;
  background: url("../../../assets/images/list/dot.png") no-repeat 0 6px;
  padding-left: 15px;
}

.list .list__text .people {
  display: block;
  margin-bottom: 5px;
  background: url("../../../assets/images/list/dot.png") no-repeat 0;
  padding-left: 15px;
}

.tab-header .category-tabs {
  display: inline-block;
}

.learning-guide .el-dialog {
  .el-dialog__body {
    padding: 15px 20px !important;
    border-top: 1px solid #e5e5e5;
  }
}

.tags {
  position: absolute;
  top: 136px;
  left: 220px;
  li {
    display: inline-block;
    width: 56px;
    height: 24px;
    line-height: 24px;
    text-align: center;
    background-color: #bf9c51;
    color: #fff;
    margin-right: 5px;
    margin-bottom: 5px;
  }
}
.list .bottom {
  width: 48%;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: absolute;
  left: 50%;
  bottom: 12px;
}
</style>
